package com.xnyzc.lhy.order.controller.dapi.driver;

import com.xnyzc.lhy.common.entity.Rv;
import com.xnyzc.lhy.common.exception.PangException;
import com.xnyzc.lhy.common.penum.EErrorCode;
import com.xnyzc.lhy.common.util.CheckUtil;
import com.xnyzc.lhy.common.util.TokenUtil;
import com.xnyzc.lhy.order.entity.param.auth.SmsCode;
import com.xnyzc.lhy.order.service.driver.IOaDPersonalDetailsService;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @Description 司机个人中心
 * @Author zhuyubin
 * @Date 2019/8/2 16:31
 **/
@RestController
@RequestMapping(value = "dapi/driverPersonalDetails")
public class DriverPersonalDetailsController {

    @Autowired
    private IOaDPersonalDetailsService iOaDPersonalDetailsService;

    /**
     * 司机设置个人中心获取页面数据
     *
     * @return
     */
    @GetMapping(value = "getDriverPersonalDetails")
    public Rv getDriverPersonalDetails() {
        Long driverId = TokenUtil.getTokenUserId();
        if (CheckUtil.objIsEmpty(driverId)) {
            throw PangException.create(EErrorCode.tokenExpire);
        }
        String userType = TokenUtil.getUserType();
        if (CheckUtil.strIsEmpty(userType)) {
            throw PangException.create(EErrorCode.missingAuthArgs);
        }
        return Rv.wrap(iOaDPersonalDetailsService.getPersonalDetails(driverId));
    }

    /**
     * 司机获取车辆资料
     */
    @GetMapping(value = "getCarDetails")
    public Rv getCarDetails() {
        Long driverId = TokenUtil.getTokenUserId();
        return iOaDPersonalDetailsService.getCarDetails(driverId);
    }

    /**
     * 获取司机手机号
     */
    @GetMapping(value = "getDriverPhone")
    public Rv getDriverPhone() {
        Long driverId = TokenUtil.getTokenUserId();
        return iOaDPersonalDetailsService.getDriverPhone(driverId);
    }

    /**
     * 修改手机号验证
     */
    @PostMapping(value = "checkPhoneCode")
    public Rv checkPhoneCode(
            @RequestBody SmsCode smsCode
    ) {
        return iOaDPersonalDetailsService.checkPhoneCode(smsCode);
    }

    /**
     * 清除司机每月可修改手机号的次数
     */
    @GetMapping(value = "reFushUpdatePhoneCount")
    public void reFushUpdatePhoneCount() {
        iOaDPersonalDetailsService.reFushUpdatePhoneCount();
    }

    /**
     * 司机退出登录判断有没有打卡
     * @return
     */
    @GetMapping(value = "signOut")
    public Rv signOut() {
        return iOaDPersonalDetailsService.signOut();
    }

    /**
     * 司机切换头像
     * @param file 头像文件
     * @return
     */
    @PostMapping(value = "updateHead")
    public Rv updateHead(
            @ApiParam(name = "file", value = "文件") @RequestPart("file") MultipartFile file
            ) {
        return iOaDPersonalDetailsService.updateHead(file);
    }

    /**
     * 司机状态检查
     */
    @GetMapping(value = "statusCheck")
    public Rv statusCheck() {
        return iOaDPersonalDetailsService.statusCheck();
    }

}
